package src;

import javax.swing.*;
import java.awt.*;

public class AdminMainFrame extends JFrame {
    public AdminMainFrame() {
        setTitle("管理员系统");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 创建主面板
        JPanel mainPanel = new JPanel(new BorderLayout());
        
        // 创建菜单栏
        JMenuBar menuBar = new JMenuBar();
        
        // 客户管理菜单
        JMenu customerMenu = new JMenu("客户管理");
        JMenuItem addCustomer = new JMenuItem("添加客户");
        JMenuItem queryCustomer = new JMenuItem("查询客户");
        JMenuItem modifyCustomer = new JMenuItem("修改客户");
        JMenuItem deleteCustomer = new JMenuItem("删除客户");
        JMenuItem exportCustomer = new JMenuItem("导出客户数据");
        
        customerMenu.add(addCustomer);
        customerMenu.add(queryCustomer);
        customerMenu.add(modifyCustomer);
        customerMenu.add(deleteCustomer);
        customerMenu.add(exportCustomer);
        
        // 银行卡管理菜单
        JMenu cardMenu = new JMenu("银行卡管理");
        JMenuItem addCard = new JMenuItem("添加银行卡");
        JMenuItem queryCard = new JMenuItem("查询银行卡");
        JMenuItem modifyCard = new JMenuItem("修改银行卡");
        JMenuItem deleteCard = new JMenuItem("删除银行卡");
        JMenuItem exportCard = new JMenuItem("导出银行卡数据");
        
        cardMenu.add(addCard);
        cardMenu.add(queryCard);
        cardMenu.add(modifyCard);
        cardMenu.add(deleteCard);
        cardMenu.add(exportCard);
        
        // 存款业务管理菜单
        JMenu depositMenu = new JMenu("存款业务管理");
        JMenuItem addDeposit = new JMenuItem("添加存款业务");
        JMenuItem queryDeposit = new JMenuItem("查询存款业务");
        JMenuItem modifyDeposit = new JMenuItem("修改存款业务");
        JMenuItem deleteDeposit = new JMenuItem("删除存款业务");
        JMenuItem exportDeposit = new JMenuItem("导出存款业务数据");
        
        depositMenu.add(addDeposit);
        depositMenu.add(queryDeposit);
        depositMenu.add(modifyDeposit);
        depositMenu.add(deleteDeposit);
        depositMenu.add(exportDeposit);
        
        // 交易管理菜单
        JMenu transactionMenu = new JMenu("交易管理");
        JMenuItem queryTransaction = new JMenuItem("查询交易");
        JMenuItem deleteTransaction = new JMenuItem("删除交易");
        JMenuItem exportTransaction = new JMenuItem("导出交易数据");
        
        transactionMenu.add(queryTransaction);
        transactionMenu.add(deleteTransaction);
        transactionMenu.add(exportTransaction);
        
        // 添加菜单到菜单栏
        menuBar.add(customerMenu);
        menuBar.add(cardMenu);
        menuBar.add(depositMenu);
        menuBar.add(transactionMenu);
        
        // 添加菜单栏到主面板
        mainPanel.add(menuBar, BorderLayout.NORTH);
        
        // 添加事件监听器
        addCustomer.addActionListener(e -> new CustomerDialog(this, "添加客户").setVisible(true));
        queryCustomer.addActionListener(e -> new CustomerQueryDialog(this).setVisible(true));
        modifyCustomer.addActionListener(e -> new CustomerDialog(this, "修改客户").setVisible(true));
        deleteCustomer.addActionListener(e -> new CustomerDeleteDialog(this).setVisible(true));
        exportCustomer.addActionListener(e -> exportCustomerData());
        
        addCard.addActionListener(e -> new CardDialog(this, "添加银行卡").setVisible(true));
        queryCard.addActionListener(e -> new CardQueryDialog(this).setVisible(true));
        modifyCard.addActionListener(e -> new CardDialog(this, "修改银行卡").setVisible(true));
        deleteCard.addActionListener(e -> new CardDeleteDialog(this).setVisible(true));
        exportCard.addActionListener(e -> exportCardData());
        
        addDeposit.addActionListener(e -> new DepositDialog(this, "添加存款业务").setVisible(true));
        queryDeposit.addActionListener(e -> new DepositQueryDialog(this).setVisible(true));
        modifyDeposit.addActionListener(e -> new DepositDialog(this, "修改存款业务").setVisible(true));
        deleteDeposit.addActionListener(e -> new DepositDeleteDialog(this).setVisible(true));
        exportDeposit.addActionListener(e -> exportDepositData());
        
        queryTransaction.addActionListener(e -> new TransactionQueryDialog(this).setVisible(true));
        deleteTransaction.addActionListener(e -> new TransactionDeleteDialog(this).setVisible(true));
        exportTransaction.addActionListener(e -> exportTransactionData());
        
        // 添加退出按钮
        JButton logoutButton = new JButton("退出登录");
        logoutButton.addActionListener(e -> {
            new MainFrame().setVisible(true);
            this.dispose();
        });
        
        JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        bottomPanel.add(logoutButton);
        mainPanel.add(bottomPanel, BorderLayout.SOUTH);
        
        add(mainPanel);
    }
    
    private void exportCustomerData() {
        // TODO: 实现导出客户数据到CSV的功能
        JOptionPane.showMessageDialog(this, "导出客户数据功能待实现");
    }
    
    private void exportCardData() {
        // TODO: 实现导出银行卡数据到CSV的功能
        JOptionPane.showMessageDialog(this, "导出银行卡数据功能待实现");
    }
    
    private void exportDepositData() {
        // TODO: 实现导出存款业务数据到CSV的功能
        JOptionPane.showMessageDialog(this, "导出存款业务数据功能待实现");
    }
    
    private void exportTransactionData() {
        // TODO: 实现导出交易数据到CSV的功能
        JOptionPane.showMessageDialog(this, "导出交易数据功能待实现");
    }
} 